package com.ad.pet.common.structure.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.ad.pet.R;
import com.ad.pet.common.structure.ui.activity.BaseActivity;
import com.ad.pet.common.structure.ui.control.AppToolbar;


/**
 * Created by z on.
 * Des:带有toolbar
 * Date: 2017/3/8
 */

public abstract class AppToolbarFragment extends LoadingFragment {

    protected AppToolbar mToolbar;

    @Override
    public int initContentView() {
        return R.layout.activity_apptoolbar;
    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mToolbar = findViewById(R.id.toolbar);
        initToolbar();
        init();
    }

    private void initToolbar() {
        mToolbar.setTitleTextColor(mFragment.getResources().getColor(R.color.white));
        mToolbar.setBackOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
        ((BaseActivity) getActivity()).setSupportActionBar(mToolbar);
    }

    protected void init() {
    }
//    protected void setToolbar(Toolbar toolbar) {
//        setSupportActionBar(toolbar);
//        ActionBar bar =
//                getSupportActionBar();
//        bar.setDisplayHomeAsUpEnabled(true);
//        bar.setHomeButtonEnabled(true);
//    }


    protected void setToolbarNext(String text, View.OnClickListener listener) {
        mToolbar.setNextText(text);
        mToolbar.setNextOnClickListener(listener);

    }

    protected void hideRigth() {
        mToolbar.hideRigth();

    }

    protected void setLeftEnabled() {
        mToolbar.setLeftEnabled();
        mToolbar.isDispayBackIcon(false);
    }

    protected void setToolbarNext(View.OnClickListener listener) {
        mToolbar.setNextOnClickListener(listener);

    }

    protected String title() {
        return "标题";
    }


    public void setToolbarNext(String text) {
        mToolbar.setNextText(text);
    }

    public void setToolbarTitle(String title) {
        if (mToolbar == null) return;
        mToolbar.setTitle(title);
    }

}
